import ZmUpload from '@/components/ZmUpload/components/main'
import { getBaseData } from '@/utils/store'
import { SALE_ORDER_TYPE } from '@/model/type'
export const OPERATE_TAB = [
  {
    value: 'dataInfo',
    label: '概况信息'
  },
  {
    value: 'outstandInfo',
    label: '回款记录'
  },
  {
    value: 'invoiceInfo',
    label: '发票记录'
  },
  {
    value: 'activeInfo',
    label: '卡券激活'
  },
  {
    value: 'refundInfo',
    label: '退货记录'
  }
]

export const base = (info) => {
  const isTypeFour = info.form.saleType === '4'
  const isTypeSix = info.form.saleType === '6'
  return [
    { name: '回款计划编号', label: 'planOrderNo' },
    { name: '销售单类型', label: 'typeName' },
    {
      hide: isTypeFour,
      name: '业务类型',
      label: 'businessTypeName'
    },
    { name: '订单状态', label: 'statusName' },
    { name: '销售单名称', label: 'name' },
    { name: '销售单号', label: 'orderNo' },
    {
      name: '关联客户',
      // label: 'customerName',
      render: (h, row) => {
        return (
          <el-button
            type="text"
            onClick={() => {
              info.onExtendShow(info.form.customerId, 'customer')
            }}
          >
            {info.form.customerName}
          </el-button>
        )
      }
    },
    { name: '客户类型', label: 'customerTypeName' },
    {
      name: '签约主体',
      render: (h) => {
        return [
          <span>
            {info.form.companyType === '1' ? '福州爱来有限公司' : '福建中瑞心选科技有限责任公司'}
          </span>
        ]
      }
    },
    /* { name: '订单总金额', label: 'saleTotalPrice' },
    { name: '预估绩效提成', label: 'proportionPrice' }, */
    { name: '合同形式', label: 'contractTypeName' },
    // 回款计划 详情 新增业务场景字段
    // {
    //   hasIcon: true,
    //   name: '业务场景',
    //   label: 'businessSceneName'
    // },
    // {
    //   name: '相关附件',
    //   // label: "enclosureUrl",
    //   render: (h, row, index) => {
    //     return [
    //       info.form.enclosureUrl ? (
    //         <el-button
    //           type="text"
    //           size="mini"
    //           class="pt10"
    //           onClick={() => {
    //             info.onExport(info.form.enclosureUrl)
    //           }}
    //         >
    //           {info.form.enclosureUrlName}
    //         </el-button>
    //       ) : (
    //         <div class=" ">无附件</div>
    //       )
    //     ]
    //   }
    // },

    // 回款计划
    // {
    //   hasIcon: true,
    //   // hide: isTypeThree,
    //   name: '相关附件',
    //   render: h => {
    //     // const saleTypeList = ['1', '2', '3', '4', '5']
    //     return [
    //       <div class="df-center">
    //         <span class="dib" v-show={!info.form.enclosureUrl}>
    //           无附件
    //         </span>
    //         <zm-enclosure
    //           v-show={info.form.enclosureUrl}
    //           fileUrl={info.form.enclosureUrl}
    //         />
    //         <ZmUpload
    //           // v-show={saleTypeList.includes(context.saleOrderType)}
    //           class="ml5"
    //           http-request={info.fileUpload}
    //           accept=".rar,.zip,.doc,.docx,.pdf,.png,.jpg,.pptx"
    //           limit={1}
    //           single-file-size={5}
    //         >
    //           <zm-button size="mini">
    //             {!info.form.enclosureUrl ? '上传' : '替换'}
    //           </zm-button>
    //         </ZmUpload>
    //       </div>
    //     ]
    //   }
    // },

    { name: '签单日期', label: 'signDate' },
    { name: '发票类型', label: 'invoiceTypeName' },
    { name: '归属业务员', label: 'salesmanName' },
    { name: '归属部门', label: 'apartmentName' },
    { name: '预填开票主体', label: 'invoiceContent' },
    {
      name: '备注信息',
      // label: "remark",
      render: (h) => {
        return [<span>{isTypeSix ? info.form.product.productList.remark : info.form.remark}</span>]
      }
    },
    {
      hide: isTypeFour || isTypeSix,
      name: '密钥',
      label: 'secretNo'
    },
    { name: '结算方式', label: 'settlementTypeName' },
    {
      hide: !isTypeFour,
      label: 'saleTotalPrice',
      name: '销售单总价'
    },
    {
      hide: !isTypeFour,
      label: 'number',
      name: '包场人数'
    },
    {
      hide: !isTypeFour,
      label: 'salePrice',
      name: '销售单单价'
    },
    {
      hide: !isTypeFour,
      // hasIcon: isTypeFour,
      name: '预估提成',
      label: 'proportionPrice'
    }
  ]
}

export const outStand = (info) => {
  return [
    { name: '退款金额', label: 'refundTotalPrice' },
    { name: '实际应收(元)', label: 'receivable' },
    { name: '已回款金额(元)', label: 'returnedMoney' },
    { name: '剩余应收(元)', label: 'residue' },
    { name: '已开票金额', label: 'invoiceAmount' },
    { name: '未开票金额', label: 'noAmount' }
  ]
}

// 产品信息
// <!-- saleType 销售方式id，1纸质，2电子 -->
//         <!-- 类型：1兑换券，2卖品券，3点卡，4次卡，5优惠券 -->
export const product = (info) => {
  return [
    { name: '产品编号', label: 'productCode', valueClass: 'vm  ' },
    {
      name: '产品名称',
      valueClass: 'vm  ',
      label: 'productName'
      /* render: (h, row, index) => {
        return [
          <el-button
            type="text"
            size="mini"
            class="pt10"
            onClick={() => {
              info.onExtendShow(info.form.product.productId, "product");
            }}
          >
            {info.form.product.productName}
          </el-button>
        ];
      } */
    },
    { name: '产品类型', label: 'productTypeName', valueClass: 'vm  ' },
    { name: '业务类型', label: 'businessTypeName', valueClass: 'vm  ' },

    {
      name: '次卡绑定产品',
      label: 'couponProductName',
      valueClass: 'vm  ',
      hide: info.form.product.productType !== '4'
    },

    { name: '售货方式', label: 'saleTypeName', valueClass: 'vm  ' }, // 次卡产品信息
    {
      hide: info.form.product.productType === '5',
      name: '产品面值',
      label: 'parValue',
      valueClass: 'vm  '
    },
    {
      hide: info.form.product.productType !== '5',
      name: '优惠券面值',
      label: 'parValue',
      valueClass: 'vm  '
    },

    {
      name: '理论成本',
      label: 'theoryCostPrice',
      valueClass: 'vm  ',
      hide: info.form.product.productType !== '3'
    },
    {
      name: '实际成本',
      label: 'practiceCostPrice',
      valueClass: 'vm  ',
      hide: info.form.product.productType !== '3'
    },
    {
      name: '销售比例',
      valueClass: 'vm  ',
      hide: info.form.product.productType !== '3',
      render: (h) => {
        return [
          <span>{info.form.product.saleScalePrice + ':' + info.form.product.saleScalePoint}</span>
        ]
      }
    },
    {
      name: '消费比例',
      valueClass: 'vm  ',
      hide: info.form.product.productType !== '3',
      render: (h) => {
        return [
          <span>
            {info.form.product.consumptionScalePrice +
              ':' +
              info.form.product.consumptionScalePoint}
          </span>
        ]
      }
    },
    {
      hide: info.form.product.productType !== '3',
      name: '销售类型',
      render: (h) => {
        return [<span>{info.form.product.isCustomize === '1' ? '自定义金额' : '统一金额'}</span>]
      }
    },
    {
      name: '销售单价(元)',
      label: 'salePrice',
      valueClass: 'vm  ',
      hide: info.form.product.productType === '4'
    },
    {
      name: '销售单价(元)',
      valueClass: 'vm  ',
      hide: info.form.product.productType !== '4',
      render: (h) => {
        return [<span>{info.form.product.salePriceName}</span>]
      }
    },
    { name: '销售单总额(元)', label: 'saleTotalPrice', valueClass: 'vm  ' },
    {
      hide: info.form.product.productTypeId === '4', // 不为次卡
      name: '转赠配置',
      render: (h) => {
        return [<span>{info.form.product.isGive === '1' ? '可转赠' : '不可转赠'}</span>]
      }
    },
    { name: '数量(张)', label: 'number', valueClass: 'vm  ' },

    { name: '提成', label: 'proportion', valueClass: 'vm  ', unit: '%' },
    { name: '预估提成(元)', label: 'proportionPrice', valueClass: 'vm  ' },
    {
      name: '销售折扣',
      valueClass: 'vm  ',
      hide: info.form.product.productType !== '3',
      render: (h) => {
        return [<span>{info.form.cardSaleScale || '--'}%</span>]
      }
    },
    { name: '有效期类型', label: 'expiredTypeName', valueClass: 'vm  ' },
    { name: '有效期', label: 'expireTime', valueClass: 'vm  ' },
    { name: '备注说明', label: 'remark', valueClass: 'vm  ' }
  ]
}

// outStand 回款记录
export const outStandColumns = (ctx) => {
  return [
    {
      prop: 'returnedNo',
      label: '回款编号'
    },

    {
      prop: 'returnedTime',
      label: '回款日期'
    },

    {
      prop: 'returnedTypeName',
      label: '回款类型'
    },
    {
      prop: 'operator',
      label: '回款操作人'
    },
    {
      prop: 'salesmanName',
      label: '回款所属业务员'
    },
    {
      // prop: 'returnedPeriods',
      label: '回款期数',
      render: (h, row) => {
        return [<span>第{row.returnedPeriods}期</span>]
      }
    },
    // 回款计划详情中的回款记录增加 '本期回款提成' 字段
    {
      prop: 'returnedPrice',
      label: '本期回款提成'
    },
    {
      label: '回款金额(元)',
      render: (h, row) => {
        return row.returnedMoney > 0 ? (
          <span>{row.returnedMoney}</span>
        ) : (
          <span class="fc-error">{row.returnedMoney}</span>
        )
      }
    },
    // {
    //   prop: 'balanceAmount',
    //   label: '红冲金额(元)'
    // },
    {
      prop: 'gatheringName',
      label: '收款单位'
    },
    {
      prop: 'transactionNo',
      label: '交易流水号'
    },
    {
      // prop: "customerId",
      label: '逾期状态',
      render: (h, row) => {
        const style =
          row.overdueStatus === '1'
            ? 'el-button--success pd5 bd-r8'
            : row.overdueStatus === '2'
              ? 'el-button--danger pd5 bd-r8'
              : ''
        return (
          <el-button plain class={style}>
            {row.overdueStatusName}
          </el-button>
        )
      }
    },
    {
      prop: 'overdueDay',
      label: '逾期天数(天)'
    },
    {
      label: '回款凭证',
      render: (h, row) => {
        const res = row.enclosureUrl ? <zm-enclosure fileUrl={row.enclosureUrl} /> : <span>--</span>
        return res
      }
    },
    {
      prop: 'remark',
      label: '备注'
    }
  ]
}

// invoice 发票记录
export const invoiceColumns = (ctx) => {
  return [
    {
      prop: 'makeTime',
      label: '开票日期'
    },

    {
      label: '发票状态',
      render: (h, row) => {
        const style =
          row.isRecycle === '1'
            ? 'el-button--success plr10 ptb5 bd-r8 fs14'
            : row.isRecycle === '2'
              ? 'el-button--danger plr10 ptb5 bd-r8 fs14'
              : ''
        return (
          <el-button plain class={style}>
            {row.recycleName}
          </el-button>
        )
      }
    },

    {
      prop: 'amount',
      label: '开票金额'
    },
    {
      prop: 'invoiceTypeName',
      label: '票据类型'
    },
    {
      prop: 'invoiceNumber',
      label: '发票号码'
    },
    {
      prop: 'invoiceMain',
      label: '开票主体'
    },
    {
      prop: 'invoiceCoding',
      label: '发票代码'
    },
    {
      prop: 'operator',
      label: '开票操作人'
    },
    {
      prop: 'updateTime',
      label: '录入时间'
    },
    {
      prop: 'billRemark',
      label: '发票内容'
    }
  ]
}

// refund 退票记录
export const refundColumns = (ctx) => {
  return [
    {
      prop: 'orderNo',
      label: '销售单号'
    },

    {
      prop: 'createTime',
      label: '退货时间'
    },
    {
      prop: 'productName',
      label: '退货产品'
    },
    {
      prop: 'refundNumber',
      label: '退货数量(张)'
    },
    {
      prop: 'refundAmount',
      label: '退货金额(元)'
    },
    {
      prop: 'remark',
      label: '备注'
    }
  ]
}

// active 卡券激活
export const activeInfoList = (ctx) => {
  let labelName =
    ctx.activeData.productType === '3' || ctx.activeData.productType === '4'
      ? '卡号区间'
      : '券号区间'
  return [
    { label: 'expiredType', name: '有效期类型' },
    { label: 'expiredTime', name: '有效期' },
    {
      hide: ctx.activeData.saleType === '2',
      label: 'codeIdDetail',
      name: labelName
    },
    { label: 'activeAccount', name: '激活操作人' },
    { label: 'activeTime', name: '激活时间' }
  ]
}

export const cinemaInfoList = [
  {
    name: '选择影院',
    type: 'cinemaType'
  },
  {
    name: '影院列表',
    type: 'url'
  },
  {
    name: '影片',
    type: 'filmName'
  },
  {
    hasIcon: true,
    name: '包场时间',
    type: 'date',
    start: 'startDate',
    end: 'endDate'
  },
  {
    hasIcon: true,
    name: '影厅备注',
    label: 'hallRemark'
  }
]

// 文旅
export const wenlv = (ctx) => {
  return [
    {
      name: '活动类型',
      label: 'typeName'
    },
    {
      name: '活动场地',
      label: 'address'
    },
    {
      name: '活动时间',
      type: 'date',
      start: 'startTime',
      end: 'endTime'
    },
    {
      name: '销售单总价计算方式',
      label: 'calculationMethodName'
    },
    {
      name: '销售单单价',
      label: 'unitPrice'
    },
    {
      name: '活动人数',
      label: 'joinCount'
    },
    {
      name: '销售单总价',
      label: 'totalSalePrice'
    },
    {
      name: '活动备注',
      label: 'remark'
    }
  ]
}

export const cinemaColumns = (ctx) => {
  return [
    {
      prop: 'cinemaName',
      label: '影院名称'
    },
    {
      prop: 'cinemaCode',
      label: '影院编码'
    },
    {
      prop: 'interfaceName',
      label: '系统商'
    },
    {
      prop: 'cinemaLineName',
      label: '院线'
    },
    {
      label: '地区',
      render: (h, row) => {
        return [
          <span>
            {row.provinceName}-{row.cityName}-{row.countyName}
          </span>
        ]
      }
    }
  ]
}

export const productListColumns = (ctx) => {
  return [
    {
      prop: 'name',
      label: '商品名称'
    },
    {
      prop: 'price',
      label: '销售单价'
    },
    {
      prop: 'number',
      label: '数量'
    },
    {
      prop: 'deliveryMoney',
      label: '运费'
    },
    {
      label: '商品总额',
      render: (h, row) => {
        return <span>{(+row.price * +row.number + (+row.deliveryMoney || 0)).toFixed(2)}</span>
      }
    }
  ]
}

export const sendCouponInfo = (info) => {
  return [
    { name: '方案ID', label: 'id' },
    { name: '方案名称', label: 'name' },
    { name: '有效期', label: 'timeTypeDes' },
    { name: '方案类型', label: 'typeDes' },
    // 如果 方案类型为1:根据销售单绑定卡券数量 则不显示 支付类型
    { hide: info.CouponInfo.type === '1', name: '支付类型', label: 'payTypeDes' },
    { name: '触发场景', label: 'sceneDes' },
    { name: '使用产品', label: 'productTypeDes' },
    { name: '领取方式', label: 'receiveTypeDes' },
    { name: '修改日期', label: 'updateTime' }
  ]
}

export const uploadStatusList = [
  // 附件状态
  {
    name: '全部',
    value: '-1'
  },
  {
    name: '有附件',
    value: '1'
  },
  {
    name: '无附件',
    value: '2'
  }
]
export const receiptStatusList = [
  {
    name: '全部',
    value: '-1'
  },
  {
    name: '已回执',
    value: '1'
  },
  {
    name: '未回执',
    value: '2'
  }
]

export const columns = ctx => {
  return [
    {
      label: '销售单类型',
      headCheck: '1',
      minWidth: 120,
      render: (h, row) => {
        return [
          <el-tag size="medium" type={SALE_ORDER_TYPE[row.typeName] || 'primary'}>
            {row.typeName || '-'}
          </el-tag>
        ]
      }
    },
    {
      prop: 'planOrderNo',
      headCheck: '1',
      label: '回款计划编号'
    },
    {
      prop: 'status',
      label: '订单状态',
      width: 120,
      headCheck: '1',
      render: (h, row) => {
        const list = getBaseData()
        let res = list.orderStatus.find(item => {
          return item.value === row.status || !row.status || row.status === '0'
        })
        switch (res.value) {
          case '1':
            res.style = 'success'
            break
          case '2':
            res.style = 'danger'
            break
          case '3':
            res.style = 'warning'
            break
          case '4':
            res.style = 'primary'
            break
          default:
            res.style = 'primary'
            break
        }
        return [
          <el-tag size="medium" type={res.style}>
            {res.name}
          </el-tag>
        ]
      }
    },
    {
      prop: 'payStatus',
      label: '回款状态',
      width: 120,
      headCheck: '1',
      render: (h, row) => {
        const list = getBaseData()
        let res = list.payStatus.find(item => {
          return (
            item.value === row.payStatus || !row.payStatus || row.payStatus === '0'
          )
        })
        switch (res.value) {
          case '1':
            res.style = 'primary'
            break
          case '2':
            res.style = 'warning'
            break
          case '3':
            res.style = 'success'
            break
          case '4':
            res.style = 'danger'
            break
          default:
            res.style = 'primary'
            break
        }
        //  plr10 ptb5 bd-r8 fs14
        return [
          <el-tag size="medium" type={res.style}>
            {res.name}
          </el-tag>
        ]
      }
    },
    {
      prop: 'orderNo',
      headCheck: '1',
      label: '销售单号'
    },
    {
      prop: 'name',
      label: '销售单名称',
      headCheck: '1',
      minWidth: 150,
      render: (h, row) => {
        return [
          <el-button
            type="text"
            onClick={() => {
              ctx.onExtendShow(row.saleId, 'sale')
            }}
          >
            {row.saleName}
          </el-button>
        ]
      }
    },
    {
      prop: 'customerName',
      headCheck: '0',
      label: '关联客户'
    },
    {
      prop: 'checkStatusName',
      headCheck: '0',
      label: '审批状态'
    },
    {
      prop: 'salesmanName',
      headCheck: '1',
      label: '归属业务员'
    },
    {
      prop: 'saleTotalPrice',
      headCheck: '1',
      label: '销售总额(元)'
    },
    {
      prop: 'refundTotalPrice',
      headCheck: '1',
      label: '退款金额(元)'
    },
    {
      prop: 'refundNumber',
      headCheck: '0',
      label: '退货数量'
    },
    {
      prop: 'actualReceivable',
      headCheck: '1',
      label: '实际应收(元)'
    },
    {
      prop: 'yetReturnedMoney',
      headCheck: '1',
      label: '已回款总额(元)'
    },
    {
      prop: 'residue',
      headCheck: '1',
      label: '剩余应收（元）'
    },
    {
      prop: 'invoiceAmount',
      headCheck: '0',
      label: '已开票金额（元）'
    },
    {
      prop: 'settlementTypeName',
      headCheck: '0',
      label: '结算方式'
    },
    {
      prop: 'productName',
      headCheck: '0',
      label: '产品名称'
    },
    {
      prop: 'number',
      headCheck: '0',
      label: '数量'
    },
    {
      prop: 'validityTime',
      headCheck: '0',
      label: '产品有效期'
    },
    {
      prop: 'saleTypeName',
      headCheck: '0',
      label: '售货方式'
    },
    {
      prop: 'salePrice',
      headCheck: '0',
      label: '销售单价'
    },
    {
      prop: 'activeTime',
      headCheck: '0',
      label: '距激活日期天数'
    },
    {
      prop: 'proportion',
      headCheck: '0',
      label: '提成比例'
      /* render: (h, row) => {
        return <span>{row.proportion}%</span>
      } */
    },
    {
      prop: 'cardSaleScale',
      headCheck: '0',
      label: '销售折扣(%)'
    },
    {
      prop: 'proportionPrice',
      headCheck: '0',
      label: '预估绩效提成'
    },
    {
      prop: 'actualProportionPrice',
      headCheck: '0',
      label: '实际绩效提成'
    },
    {
      prop: 'invoiceTypeName',
      headCheck: '0',
      label: '发票类型'
    },
    {
      prop: 'invoiceMain',
      headCheck: '0',
      label: '开票主体'
    },
    {
      prop: 'companyTypeName',
      headCheck: '0',
      label: '我方信息'
    },
    {
      prop: 'contractTypeName',
      headCheck: '0',
      label: '合同形式'
    },
    {
      prop: 'signDate',
      headCheck: '0',
      label: '签单日期'
    },
    {
      prop: 'apartmentName',
      headCheck: '0',
      label: '归属部门'
    },
    {
      prop: 'remark',
      headCheck: '0',
      label: '备注信息'
    },
    {
      prop: 'overdueDay',
      headCheck: '1',
      label: '逾期天数(天)'
    },
    {
      prop: 'planReturnedTime',
      headCheck: '1',
      label: '计划回款日期'
    },
    {
      button: true,
      label: '操作',
      headFixed: '1',
      fixed: 'right',
      width: 80,
      render: (h, row) => {
        return (
          <el-button
            type="text"
            onClick={() => {
              ctx.onDetail(row)
            }}
          >
            详情
          </el-button>
        )
      }
    }
  ]
}
